package com.scale.service.conversation.controller;

import com.example.common.result.Result;
import com.scale.service.conversation.service.MessagesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 对话消息表 前端控制器
 * </p>
 *
 * @author crp
 * @since 2025-09-24
 */
@Api(tags = "消息状态管理")
@RestController
@RequestMapping("/api/messages")
@CrossOrigin(origins = {
    "http://localhost:3000", 
    "http://127.0.0.1:3000", 
    "http://localhost:3001", 
    "http://127.0.0.1:3001", 
    "http://localhost:5173", 
    "http://127.0.0.1:5173"
}, maxAge = 3600, allowedHeaders = "*", allowCredentials = "true")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 更新消息状态
     */
    @ApiOperation("更新消息状态")
    @PutMapping("/{id}/status")
    public Result<Void> updateMessageStatus(
            @ApiParam("消息ID") @PathVariable Long id,
            @ApiParam("状态：read-已读, processing-处理中, failed-失败") @RequestParam String status) {
        
        boolean success = messagesService.updateMessageStatus(id, status);
        if (success) {
            return Result.success("状态更新成功", null);
        } else {
            return Result.error("状态更新失败");
        }
    }
}

